*************************************************************************************************
*																								*
*						Careers - Summary stats												*
*						name file: summary_stats.do											*
*						date: Jan 15, 2025														*
*																								*
*************************************************************************************************



*!! Make sure we keep everyone aged 20 to 65, born between 1940 and 1977.

* ---> For convenience, rename & label variables here
rename bipman_ev BD
rename bdsib_ev BDSIB
rename depranx_ev DEPRANX
rename schizo_ev SCHIZO

* Note: all the variables above should be defined based on ever diagnosed + ever prescribed specific medications

rename earnings EARN
rename totalincome INC
rename disab DISAB
rename female FEMALE
rename birthcohort BIRTHCOHORT
rename year YEAR
rename momid MOMID
rename college COLLEGE // NOTE: This should be a variable equal to one for all people who have at least a college degree - doesn't vary within people
rename highschool HS // NOTE: This should be a variable equal to one for all people who have at least a HS degree - doesn't vary within people
rename married MARRIED // NOTE: This should be a variable equal to one for all people who have ever been married - doesn't vary within people
rename divorced DIVORCED // NOTE: This should be a variable equal to one for all people who have even been divorced - doesn't vary within people


gen MENTAL = DEPRANX == 1 | SCHIZO == 1 | BD == 1 
replace MENTAL = . if DEPRANX == . | SCHIZO == . | BD == . | ANX == .

label var MENTAL 	"MH condition"
label var BD 		"BD"
label var BDSIB 	"BD sibling"
label var DEPRANX 		"Depr/anxiety"
label var SCHIZO 	"Schizophrenia"

* "fix" or create some variables
gen LNEARN = ln(EARN)
replace LNEARN = 0 if LNEARN == .
gen NOEARN = EARN == 0
gen LNINC = ln(INC) 
replace LNINC = 0 if LNINC == .
gen NOINC = INC == 0



* Number of siblings
egen t = tag(PNR MOMID)
bysort MOMID: egen NRSIB = sum(t)
drop t



*************************************************** DATA PREP UNTIL HERE ***************************************************


* -----> STATISTICS FOR TABLE 1

* panel 1
preserve
collapse BD DEPRANX SCHIZO POST, by(PNR)
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* panel 2
preserve
collapse BD DEPRANX SCHIZO POST (max) NOEARN, by(PNR)
keep if NOEARN == 1
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* panel 3
table POST, stat(mean EARN sd EARN)
table POST if BD == 1, stat(mean EARN sd EARN)
table POST if DEPRANX == 1, stat(mean EARN sd EARN)
table POST if SCHIZO == 1, stat(mean EARN sd EARN)

table BD, stat(mean EARN sd EARN)
table DEPRANX, stat(mean EARN sd EARN)
table SCHIZO, stat(mean EARN sd EARN)

* panel 4
preserve
collapse BD DEPRANX SCHIZO POST (max) DISAB, by(PNR)
keep if DISAB == 1
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* -----> TABLE 1, FOR MOMID != .

* panel 1
preserve
keep if MOMID != .
collapse BD DEPRANX SCHIZO POST, by(PNR)
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* panel 2
preserve
keep if MOMID != .
collapse BD DEPRANX SCHIZO POST (max) NOEARN, by(PNR)
keep if NOEARN == 1
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* panel 3
preserve 
keep if MOMID != .
table POST, stat(mean EARN sd EARN)
table POST if BD == 1, stat(mean EARN sd EARN)
table POST if DEPRANX == 1, stat(mean EARN sd EARN)
table POST if SCHIZO == 1, stat(mean EARN sd EARN)

table BD, stat(mean EARN sd EARN)
table DEPRANX, stat(mean EARN sd EARN)
table SCHIZO, stat(mean EARN sd EARN)
restore 

* panel 4
preserve
keep if MOMID != .
collapse BD DEPRANX SCHIZO POST (max) DISAB, by(PNR)
keep if DISAB == 1
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 


* -----> TABLE 1, FOR MOMID != . & NRSIB > 0 

* panel 1
preserve
keep if MOMID != . & NRSIB > 1
collapse BD DEPRANX SCHIZO POST, by(PNR)
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* panel 2
preserve
keep if MOMID != . & NRSIB > 1
collapse BD DEPRANX SCHIZO POST (max) NOEARN, by(PNR)
keep if NOEARN == 1
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 

* panel 3
preserve 
keep if MOMID != . & NRSIB > 1
table POST, stat(mean EARN sd EARN)
table POST if BD == 1, stat(mean EARN sd EARN)
table POST if DEPRANX == 1, stat(mean EARN sd EARN)
table POST if SCHIZO == 1, stat(mean EARN sd EARN)

table BD, stat(mean EARN sd EARN)
table DEPRANX, stat(mean EARN sd EARN)
table SCHIZO, stat(mean EARN sd EARN)
restore 

* panel 4
preserve
keep if MOMID != . & NRSIB > 1
collapse BD DEPRANX SCHIZO POST (max) DISAB, by(PNR)
keep if DISAB == 1
tab POST
tab BD POST, row
tab DEPRANX POST, row
tab SCHIZO POST, row
restore 


* -----> CONDITIONS, BY COHORT (Appendix Figure A3)

table BIRTHCOHORT, stat(mean BD)
table BIRTHCOHORT, stat(mean SCHIZO)
table BIRTHCOHORT, stat(mean DEPRANX)


* -----> COMORBIDITIES (Appendix Figure A1)

gen BDDEPR = BD == 1 & DEPRANX == 1
gen BDSCHIZO = BD == 1 & SCHIZO == 1
gen DEPRSCHIZO = DEPRANX == 1 & SCHIZO == 1

table BIRTHCOHORT, stat(mean BDDEPR)
table BIRTHCOHORT, stat(mean BDSCHIZO)
table BIRTHCOHORT, stat(mean DEPRSCHIZO) 



* -----> CHARACTERISTICS OF PEOPLE WITH BD, BY COHORT (Appendix Figure A4)
preserve
* Note: the WEALTH variable should be quartile of people's wealth ONLY for people with non-missing wealth.
gen OTHER = DEPRANX == 1 | SCHIZO == 1
table BIRTHCOHORT BD, stat(mean FEMALE COLLEGE WEALTH OTHER)
restore

* -----> CHARACTERISTICS OF PEOPLE WITH BD, BY AGE AND COHORT (Appendix Figure A5)
preserve
* Note: the WEALTH variable should be quartile of people's wealth ONLY for people with non-missing wealth.
gen OTHER = DEPRANX == 1 | SCHIZO == 1
gen AGE = YEAR - BIRTHCOHORT
table BIRTHCOHORT BD if AGE == 24, stat(mean FEMALE COLLEGE WEALTH OTHER)
table BIRTHCOHORT BD if AGE == 30, stat(mean FEMALE COLLEGE WEALTH OTHER)
table BIRTHCOHORT BD if AGE == 39, stat(mean FEMALE COLLEGE WEALTH OTHER)
table BIRTHCOHORT BD if AGE == 49, stat(mean FEMALE COLLEGE WEALTH OTHER)
table BIRTHCOHORT BD if AGE == 55, stat(mean FEMALE COLLEGE WEALTH OTHER)
restore


